<?php

$APPID="wxb1b8e993084028e9";
$APPSECRET="bd45985584b46309ba7edddcaabe5a66";


$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$APPID&secret=$APPSECRET";
$ret_msg = getMsg($url);
$get_json  = json_decode($ret_msg,true);
$token     = $get_json['access_token'];

#$jsonmenu = '{"button":[{"name":"活动","sub_button":[{"type":"view","name":"赛事直播","url":"http://k3-mobile.leyecloud.com/xcx/index.php?type=8&id=KSA6"},{"type":"view","name":"赛事预告","url":"http://k3-mobile.leyecloud.com/xcx/src/evtPreview/eventPreview.html"},{"type":"view","name":"赛事添加","url":"http://k3-mobile.leyecloud.com/xcx/src/addEvents/signIn.html"}]},{"name":"背景墙","type":"view","url":"http://k3-mobile.leyecloud.com/xcx/index.php?type=4&id=KSA6"},{"name":"个人中心","type":"view","url":"http://k3-mobile.leyecloud.com/xcx/index.php?type=7&id=KSA6"}]}';
$jsonmenu = '{"button":[{"name":"乐音坊","sub_button":[{"type":"view","name":"随便听听","url":"http://lestudio.leyecloud.com:88/les/release/musicpro/media/MusicPublic/playMusic.html"},{"type":"view","name":"我的作品","url":"http://lestudio.leyecloud.com:88/les/release/musicpro/media/MusicPublic/hisHomePage.html"},{"type":"view","name":"我的账户","url":"http://lestudio.leyecloud.com:88/les/release/musicpro/media/MusicPublic/count.html"} ]},{"name":"其他","sub_button":[{"type":"view","name":"扫一扫发弹幕","url":"http://lestudio.leyecloud.com:88/les/release/musicpro/media/MusicPublic/playMusic.html"},{"type":"view","name":"关于乐音坊","url":"http://lestudio.leyecloud.com:88/les/release/musicpro/media/MusicPublic/about.html"} ]}          ]}';

$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$token;
$result = https_request($url,$jsonmenu);
var_dump($result);
function https_request($url,$data = null){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}


function getMsg($url){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}






?>
